package com.server;

import com.server.service.*;

import java.io.File;
import java.io.IOException;

/**
 * Created by dream on 14-2-15.
 */
public class GeneratorMain{
    private GeneratorParams generatorParams;

    public GeneratorMain() {
    }

    public GeneratorMain(GeneratorParams generatorParams) {
        this.generatorParams = generatorParams;
    }

    public GeneratorParams getGeneratorParams() {
        return generatorParams;
    }

    public void setGeneratorParams(GeneratorParams generatorParams) {
        this.generatorParams = generatorParams;
    }

    public void generate() throws IOException {
        new ProjectGeneratorService().generateProject(this.getGeneratorParams());
        new PomGeneratorService().generatePom(this.getGeneratorParams(),null);
        new BeanGeneratorService().generateBeans(this.getGeneratorParams());
        new DaoGeneratorService().generateDaos(this.getGeneratorParams());
        new DaoImplGeneratorService().generateDaoImpls(this.getGeneratorParams());
        new ServiceGeneratorService().generateServices(this.getGeneratorParams());
        new ServiceImplGeneratorService().generateServiceImpls(this.getGeneratorParams());
        new ControllerGeneratorService().generateControllers(this.getGeneratorParams());
        new ApplicationContextGeneratorService().generate(this.getGeneratorParams());
        new HibernateCfgGeneratorService().generate(this.getGeneratorParams());
        new JdbcPropertiesGeneratorService().generate(this.getGeneratorParams());
    }

    public void generateServer() throws IOException{
        new BeanGeneratorService().generateBeans(this.getGeneratorParams());
        new DaoGeneratorService().generateDaos(this.getGeneratorParams());
        new DaoImplGeneratorService().generateDaoImpls(this.getGeneratorParams());
        new ServiceGeneratorService().generateServices(this.getGeneratorParams());
        new ServiceImplGeneratorService().generateServiceImpls(this.getGeneratorParams());
//        new ControllerGeneratorService().generateControllers(this.getGeneratorParams());
    }

    public static void main(String[] args) throws IOException {
        String properties = System.getProperty("user.dir");
        File file = new File(properties);
        String parent = file.getParent();
        String path = parent+"/aa/";
        GeneratorParams generatorParams = new GeneratorParams();
        generatorParams.setPath(path);
        generatorParams.setClassPackage("generator.model");
        new GeneratorMain(generatorParams).generate();
    }
}
